package com.ybox.gateway.config.properties;

import com.ybox.common.core.utils.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

/**
 * 验证码配置
 *
 * @author ych
 */
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "security.captcha")
public class CaptchaProperties {
    /**
     * 验证码开关
     */
    private Boolean enabled;

    /**
     * 验证码图片宽度
     */
    private Integer width;

    /**
     * 验证码图片高度
     */
    private Integer height;

    /**
     * 验证码长度
     */
    private Integer Length;

    /**
     * 验证码类型（math 数学计算 char 字符 chineseChar 中文字符）
     */
    private String codeType;

    /**
     * 图片类型（png gif）
     */
    private String imageType;

    /**
     * 验证码字符类型
     * 类型	                 描述
     * -1                    随机
     * 1 TYPE_DEFAULT	     数字和字母混合
     * 2 TYPE_ONLY_NUMBER	 纯数字
     * 3 TYPE_ONLY_CHAR	     纯字母
     * 4 TYPE_ONLY_UPPER	 纯大写字母
     * 5 TYPE_ONLY_LOWER	 纯小写字母
     * 6 TYPE_NUM_AND_UPPER	 数字和大写字母
     */
    private String charType;

    /**
     * 字体类型
     *     Captcha.FONT_-1  随机
     *     Captcha.FONT_N ( 1 <= N <= 10 )
     */
    private String fontType;

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public String getCodeType() {
        return codeType;
    }

    public void setCodeType(String codeType) {
        this.codeType = codeType;
    }

    public String getImageType() {
        return imageType;
    }

    public void setImageType(String imageType) {
        this.imageType = imageType;
    }

    public String getCharType(){
        return charType;
    }
    public Integer getCharTypeToInt() {
        Integer result;
        switch (StringUtils.isEmpty(getCharType())?"":getCharType()){
            case "TYPE_DEFAULT": result =  1; break;
            case "TYPE_ONLY_NUMBER": result = 2; break;
            case "TYPE_ONLY_CHAR": result = 3; break;
            case "TYPE_ONLY_UPPER": result = 4; break;
            case "TYPE_ONLY_LOWER": result = 5; break;
            case "TYPE_NUM_AND_UPPER": result = 6; break;
            default: result = -1;break;
        }
        return result;
    }

    public void setCharType(String charType) {
        this.charType = charType;
    }

    public String getFontType(){
        return fontType;
    }

    public Integer getFontTypeToInt() {
        Integer result;
        switch (StringUtils.isEmpty(getFontType())?"":getFontType()){
            case "FONT_1": result = 0;break;
            case "FONT_2": result = 1;break;
            case "FONT_3": result = 2;break;
            case "FONT_4": result = 3;break;
            case "FONT_5": result = 4;break;
            case "FONT_6": result = 5;break;
            case "FONT_7": result = 6;break;
            case "FONT_8": result = 7;break;
            case "FONT_9": result = 8;break;
            case "FONT_10": result = 9;break;
            default: result = -1;break;
        }
        return result;
    }

    public void setFontType(String fontType) {
        this.fontType = fontType;
    }

    public Integer getWidth() {
        return width == null ? 0 : width;
    }

    public void setWidth(Integer width) {
        this.width = width;
    }

    public Integer getHeight() {
        return height == null ? 0 : height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getLength() {
        return Length == null ? 0 : Length;
    }

    public void setLength(Integer length) {
        Length = length;
    }
}
